//
//  BaseUINavigationController.m
//  Furniture
//
//  Created by 王小娜 on 2017/1/17.
//  Copyright © 2017年 beyondSoft. All rights reserved.
//

#import "BaseUINavigationController.h"

@interface BaseUINavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation BaseUINavigationController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.navigationBar setBackgroundImage:createImageWithUIColor([UIColor whiteColor]) forBarMetrics:(UIBarMetricsDefault)];
    
    [self setupBarButtonItemTheme];
    [self setupNavigationBarItemTheme];

}

/**
 *  设置NavigationBar主题
 */
- (void)setupNavigationBarItemTheme {
    
    UINavigationBar *appearance = [UINavigationBar appearance];
    
    //设置标题属性
    NSMutableDictionary *dictionary            = [NSMutableDictionary dictionary];
    dictionary[NSForegroundColorAttributeName] = [UIColor blackColor];
    dictionary[NSFontAttributeName]            = [UIFont systemFontOfSize:18];
    
    //设置阴影
    NSShadow *shadow = [[NSShadow alloc] init];
    [shadow setShadowOffset:CGSizeMake(0, 0)];
    dictionary[NSShadowAttributeName] = shadow;
    
    [appearance setTitleTextAttributes:dictionary];
}
- (void)setupBarButtonItemTheme {
    
    
    
    //通过appearance对象修改整个项目中所有barButtonItem的样式
    UIBarButtonItem *appearance = [UIBarButtonItem appearance];
    
    //设置普通状态的文字属性
    NSMutableDictionary *normalTextAttrs             = [NSMutableDictionary dictionary];
    normalTextAttrs[NSForegroundColorAttributeName]  = [UIColor blackColor];
    normalTextAttrs[NSFontAttributeName]             = [UIFont systemFontOfSize:15];
    [appearance setTitleTextAttributes:normalTextAttrs forState:UIControlStateNormal];
    
    //设置高亮状态的文字属性
    NSMutableDictionary *highTextAttrs               = [NSMutableDictionary dictionary];
    highTextAttrs[NSForegroundColorAttributeName]    = [UIColor blackColor];
    highTextAttrs[NSFontAttributeName]               = [UIFont systemFontOfSize:15];
    [appearance setTitleTextAttributes:highTextAttrs forState:UIControlStateHighlighted];
    
    //设置高亮状态的文字属性
    NSMutableDictionary *disableTextAttrs            = [NSMutableDictionary dictionary];
    disableTextAttrs[NSForegroundColorAttributeName] = [UIColor blackColor];
    disableTextAttrs[NSFontAttributeName]            = [UIFont systemFontOfSize:15];
    [appearance setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    // 注意：只有非根控制器才有滑动返回功能，根控制器没有。
    // 判断导航控制器是否只有一个子控制器，如果只有一个子控制器，肯定是根控制器
    if (self.childViewControllers.count == 1) {
        // 表示用户在根控制器界面，就不需要触发滑动手势，
        return NO;
    }

    
    return YES;
}

@end
